import axios from 'axios'
import commonUrl from '../common/js/commonUrl.js'
import qs from 'qs'
import {
  loadVillageId,
  loadUserId
} from '../common/js/cache.js'

// 满意度选项数据
export function getSatisfactionVote (id) {
  const url = `${commonUrl.apihost}index.php/home/Satisfaction_Vote/satisfactionVoteDetail`
  const data = {
    satisId: id,
    type: 'vote'
  }
  return axios({
    method: 'POST',
    url: url,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    data: qs.stringify(data)
  }).then((res) => {
    return Promise.resolve(res.data)
  }).catch((err) => {
    return Promise.reject(err)
  })
}

// 满意度列表的详情数据
export function getTakeInDetail (id) {
  const url = `${commonUrl.apihost}index.php/home/Satisfaction_Vote/satisfactionVoteDetail`
  const data = {
    satisId: id,
    type: 'detail'
  }
  return axios({
    method: 'POST',
    url: url,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    data: qs.stringify(data)
  }).then((res) => {
    return Promise.resolve(res.data)
  }).catch((err) => {
    return Promise.reject(err)
  })
}

// 满意度选项页面的每项详情
export function getTakeInResult (id) {
  const url = `${commonUrl.apihost}index.php/home/Satisfaction_Vote/getResultDetail`
  const data = {
    article_id: id
  }
  return axios({
    method: 'POST',
    url: url,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    data: qs.stringify(data)
  }).then((res) => {
    return Promise.resolve(res.data)
  }).catch((err) => {
    return Promise.reject(err)
  })
}

// 选举投票选项数据
export function getVotingList (id) {
  const url = `${commonUrl.apihost}index.php/home/supplement/getCandidateAllDetail`
  const data = {
    vote_id: id,
    user_id: loadUserId(),
    areas_id: loadVillageId()
  }
  return axios({
    method: 'POST',
    url: url,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    data: qs.stringify(data)
  }).then((res) => {
    return Promise.resolve(res.data)
  }).catch((err) => {
    return Promise.reject(err)
  })
}

// 事物投票数据
export function getsVoteList (id) {
  const url = `${commonUrl.apihost}index.php/home/supplement/getSupplemenAllDetail`
  const data = {
    vote_id: id,
    user_id: loadUserId(),
    areas_id: loadVillageId()
  }
  return axios({
    method: 'POST',
    url: url,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    data: qs.stringify(data)
  }).then((res) => {
    return Promise.resolve(res.data)
  }).catch((err) => {
    return Promise.reject(err)
  })
}
